﻿import QtQuick 2.15
import QtQuick.Controls 2.15
/*
  托料参数设置界面
*/

Item {
    id:backGround
    width: screenWidth
    height: 1600

    Rectangle{
        anchors.fill: backGround
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
    }

    onVisibleChanged: {
        if(visible === true)
        {
            Cpp_Connect.pageNumber = 15
        }
    }


    Rectangle{
        anchors.top: backGround.top
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 300

        Rectangle{      // 模式更改按钮 -- 检测拖料架
            id:modeSwitch_TLJ
            width: 200
            height: 100
            radius: 10
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 30
            border.width: 1
            border.color: "#f0f8ff"

            color: Cpp_Connect.TLJ_State ? "#ff3606" : "#006cee"

            // property bool flag: Cpp_Connect.TLJ_State

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.TLJ_State ? qsTr("有拖料架") : qsTr("不检测拖料架")
            }
            MouseArea{
                anchors.fill: parent

                onClicked: {
                    // parent.flag = !parent.flag
                    if(!Cpp_Connect.TLJ_State)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("499","1");
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("499","0");
                    }
                }
            }
        }


        Text{
            anchors.right: parent.right
            anchors.rightMargin: 260
            anchors.top: parent.top
            anchors.topMargin: 60
            font.pixelSize: 40
            font.bold: true
            text: qsTr("托料架安全距离")
            visible: Cpp_Connect.TLJ_State
        }

        Rectangle{
            anchors.right: parent.right
            anchors.rightMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 30
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"
            visible: Cpp_Connect.TLJ_State

            Text{
                id:aqjl_Setting_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.TLJ_Safe_Distance
            }

            TextInput{      // 拖料架安全距离输入框
                id:aqjl_Setting_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("612",aqjl_Setting_Input.text)
                    aqjl_Setting_Text.visible = true
                    aqjl_Setting_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    aqjl_Setting_Input.forceActiveFocus()
                    aqjl_Setting_Input.text = aqjl_Setting_Text.text
                    aqjl_Setting_Text.visible = false
                    aqjl_Setting_Input.visible = true
                    aqjl_Setting_Input.selectAll()
                }
            }
        }


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 70
            anchors.top: parent.top
            anchors.topMargin: 190
            font.pixelSize: 30
            font.bold: true
            text: qsTr("前 托")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 170
            anchors.top: parent.top
            anchors.topMargin: 170
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"

            color: flag ? "#ff3606" : "#006cee"

            property bool flag: false

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: parent.flag ? qsTr("开 启") : qsTr("关 闭")
            }
            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.flag = true
                    Cpp_Connect.write_modbus_rtu_Coils("115","1");
                }

                onReleased: {
                    parent.flag = false
                    Cpp_Connect.write_modbus_rtu_Coils("115","0");
                }
            }
        }

        Rectangle{          // 前托退到位 显示
            anchors.left: parent.left
            anchors.leftMargin: 90
            anchors.top: parent.top
            anchors.topMargin: 230
            width: 30
            height: 30
            radius: 30
            border.width: 1
            border.color: "black"
            color: !Cpp_Connect.Q_TLJ_Over ?  "red" : "white"
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 400
            anchors.top: parent.top
            anchors.topMargin: 190
            font.pixelSize: 30
            font.bold: true
            text: qsTr("中 托")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 500
            anchors.top: parent.top
            anchors.topMargin: 170
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"

            color: flag ? "#ff3606" : "#006cee"

            property bool flag: false

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: parent.flag ? qsTr("开 启") : qsTr("关 闭")
            }
            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.flag = true
                    Cpp_Connect.write_modbus_rtu_Coils("116","1");
                }

                onReleased: {
                    parent.flag = false
                    Cpp_Connect.write_modbus_rtu_Coils("116","0");
                }
            }
        }

        Rectangle{      // 中托退到位 显示
            anchors.left: parent.left
            anchors.leftMargin: 420
            anchors.top: parent.top
            anchors.topMargin: 230
            width: 30
            height: 30
            radius: 30
            border.width: 1
            border.color: "black"
            color: !Cpp_Connect.Z_TLJ_Over ?  "red" : "white"
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 735
            anchors.top: parent.top
            anchors.topMargin: 190
            font.pixelSize: 30
            font.bold: true
            text: qsTr("后 托")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 835
            anchors.top: parent.top
            anchors.topMargin: 170
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"

            color: flag ? "#ff3606" : "#006cee"

            property bool flag: false

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: parent.flag ? qsTr("开 启") : qsTr("关 闭")
            }
            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.flag = true
                    Cpp_Connect.write_modbus_rtu_Coils("117","1");
                }

                onReleased: {
                    parent.flag = false
                    Cpp_Connect.write_modbus_rtu_Coils("117","0");
                }
            }
        }

        Rectangle{      // 后托退到位 显示
            anchors.left: parent.left
            anchors.leftMargin: 755
            anchors.top: parent.top
            anchors.topMargin: 230
            width: 30
            height: 30
            radius: 30
            border.width: 1
            border.color: "black"
            color: !Cpp_Connect.H_TLJ_Over ?  "red" : "white"
        }

    }


    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 295
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 30
            font.bold: true
            text: qsTr("前托触发点")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 200
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:qtcfd_Setting_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.Q_TLJ_Location
            }

            TextInput{      // 前托触发点输入框
                id:qtcfd_Setting_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("1294",qtcfd_Setting_Input.text)
                    qtcfd_Setting_Text.visible = true
                    qtcfd_Setting_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    qtcfd_Setting_Input.forceActiveFocus()
                    qtcfd_Setting_Input.text = qtcfd_Setting_Text.text
                    qtcfd_Setting_Text.visible = false
                    qtcfd_Setting_Input.visible = true
                    qtcfd_Setting_Input.selectAll()
                }
            }
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"

            color: Cpp_Connect.QTLJ_Enable ? "#ff3606" : "#006cee"

            // property bool flag: false

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.QTLJ_Enable ? qsTr("有 效") : qsTr("无 效")
            }
            MouseArea{
                anchors.fill: parent

                onClicked: {

                    if(!Cpp_Connect.QTLJ_Enable)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("387","1");
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("387","0");
                    }
                }
            }
        }


        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 800
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"

            color: Cpp_Connect.Q_TLJ_LSSate ? "#ff3606" : "#006cee"

            // property bool flag: false

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.Q_TLJ_LSSate ? qsTr("小 于") : qsTr("大 于")
            }
            MouseArea{
                anchors.fill: parent

                onClicked: {

                    if(!Cpp_Connect.Q_TLJ_LSSate)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("384","1");
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("384","0");
                    }
                }
            }
        }

    }



    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 440
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 30
            font.bold: true
            text: qsTr("中托触发点")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 200
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:ztcfdxx_Setting_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.Z_TLJ_Down_Limit
            }

            TextInput{      // 中托触发点下限输入框
                id:ztcfdxx_Setting_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("296",ztcfdxx_Setting_Input.text)
                    ztcfdxx_Setting_Text.visible = true
                    ztcfdxx_Setting_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    ztcfdxx_Setting_Input.forceActiveFocus()
                    ztcfdxx_Setting_Input.text = ztcfdxx_Setting_Text.text
                    ztcfdxx_Setting_Text.visible = false
                    ztcfdxx_Setting_Input.visible = true
                    ztcfdxx_Setting_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 410
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 30
            font.bold: true
            text: qsTr("≤ 落下区间 ≤")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 640
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:ztcfdsx_Setting_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.Z_TLJ_Up_Limit
            }

            TextInput{      // 中托触发点上限输入框
                id:ztcfdsx_Setting_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("1296",ztcfdsx_Setting_Input.text)
                    ztcfdsx_Setting_Text.visible = true
                    ztcfdsx_Setting_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    ztcfdsx_Setting_Input.forceActiveFocus()
                    ztcfdsx_Setting_Input.text = ztcfdsx_Setting_Text.text
                    ztcfdsx_Setting_Text.visible = false
                    ztcfdsx_Setting_Input.visible = true
                    ztcfdsx_Setting_Input.selectAll()
                }
            }
        }

        Rectangle{
            anchors.right: parent.right
            anchors.rightMargin: 20
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"

            color: Cpp_Connect.Z_TLJ_Enable ? "#ff3606" : "#006cee"

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.Z_TLJ_Enable ? qsTr("有 效") : qsTr("无 效")
            }
            MouseArea{
                anchors.fill: parent

                onClicked: {

                    if(!Cpp_Connect.Z_TLJ_Enable)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("388","1");
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("388","0");
                    }
                }
            }
        }


    }


    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 585
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 30
            font.bold: true
            text: qsTr("后托触发点")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 200
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:htcfd_Setting_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.H_TLJ_Location
            }

            TextInput{      // 前托触发点输入框
                id:htcfd_Setting_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("1298",htcfd_Setting_Input.text)
                    htcfd_Setting_Text.visible = true
                    htcfd_Setting_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    htcfd_Setting_Input.forceActiveFocus()
                    htcfd_Setting_Input.text = htcfd_Setting_Text.text
                    htcfd_Setting_Text.visible = false
                    htcfd_Setting_Input.visible = true
                    htcfd_Setting_Input.selectAll()
                }
            }
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"
            color: Cpp_Connect.HTLJ_Enable ? "#ff3606" : "#006cee"


            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.HTLJ_Enable ? qsTr("有 效") : qsTr("无 效")
            }
            MouseArea{
                anchors.fill: parent

                onClicked: {

                    if(!Cpp_Connect.HTLJ_Enable)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("389","1");
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("389","0");
                    }
                }
            }
        }


        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 800
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#f0f8ff"
            color: Cpp_Connect.H_TLJ_LS_State ? "#ff3606" : "#006cee"

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.H_TLJ_LS_State ? qsTr("小 于") : qsTr("大 于")
            }
            MouseArea{
                anchors.fill: parent

                onClicked: {

                    if(!Cpp_Connect.H_TLJ_LS_State)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("386","1");
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("386","0");
                    }
                }
            }
        }

    }



    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 730
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 300


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 60
            font.pixelSize: 30
            font.bold: true
            text: qsTr("当前位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 210
            anchors.top: parent.top
            anchors.topMargin: 25
            width: 200
            height: 100
            radius: 10
            color: "black"
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:cureentLocation_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "aqua"
                text: Cpp_Connect.currentLocation
            }

        }


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 200
            font.pixelSize: 30
            font.bold: true
            text: qsTr("X轴当前位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 210
            anchors.top: parent.top
            anchors.topMargin: 165
            width: 200
            height: 100
            radius: 10
            color: "black"
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:cureentLocationXaxis_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "aqua"
                text: Cpp_Connect.xAxisCurrentLocation
            }

        }


        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 550
            anchors.top: parent.top
            anchors.topMargin: 25
            radius: 10
            color: "#006cee"
            border.width: 1
            border.color: "#f0f8ff"
            width: 200
            height: 100

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text: qsTr("← 左移")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#ff3606"
                    Cpp_Connect.write_modbus_rtu_Coils("21","1");
                }

                onReleased: {
                    parent.color = "#006cee"
                    Cpp_Connect.write_modbus_rtu_Coils("21","0");
                }
            }
        }

        Rectangle{
            anchors.right: parent.right
            anchors.rightMargin: 80
            anchors.top: parent.top
            anchors.topMargin: 25
            radius: 10
            color: "#006cee"
            border.width: 1
            border.color: "#f0f8ff"
            width: 200
            height: 100

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text: qsTr("右移 →")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#ff3606"
                    Cpp_Connect.write_modbus_rtu_Coils("22","1");
                }

                onReleased: {
                    parent.color = "#006cee"
                    Cpp_Connect.write_modbus_rtu_Coils("22","0");
                }
            }
        }


    }




    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 30
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 30
        radius: 10
        color: "#006cee"
        border.width: 1
        border.color: "#f0f8ff"
        width: 200
        height: 100

        Text{
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text: qsTr("返  回")
        }

        MouseArea{
            anchors.fill: parent

            onPressed: {
                parent.color = "#ff3606"
            }

            onReleased: {
                parent.color = "#006cee"
                materialRackParameter.visible = false
                advanceSettingWindow.visible = true
            }
        }
    }
}
